package com.haisen.service.impl;

import com.haisen.dataobject.entity.ItemParamValue;
import com.haisen.dataobject.mapper.base.ItemParamValueMapper;
import com.haisen.service.ItemParamValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.weekend.Weekend;
import tk.mybatis.mapper.weekend.WeekendCriteria;

import java.util.Arrays;
import java.util.List;

@Service
public class ItemParamValueServiceImpl implements ItemParamValueService {

    @Autowired
    private ItemParamValueMapper itemParamValueMapper;


    @Override
    public void create(ItemParamValue itemParamValue) {
        itemParamValueMapper.insertSelective(itemParamValue);
    }

    @Override
    public void createBatch(List<ItemParamValue> itemParamValueList) {
        itemParamValueList.forEach(e -> {
            itemParamValueMapper.insertSelective(e);
        });

    }

    @Override
    public void update(ItemParamValue itemParamValue) {
       itemParamValueMapper.updateByPrimaryKey(itemParamValue);
    }

    @Override
    public void delete(Long id) {
        itemParamValueMapper.deleteByPrimaryKey(id);
    }

    @Override
    public ItemParamValue findOneById(Long id) {
        return itemParamValueMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<ItemParamValue> findByCatId(Long itemId) {
        Weekend<ItemParamValue> weekend = Weekend.of(ItemParamValue.class);
        WeekendCriteria<ItemParamValue,Object> criteria = weekend.weekendCriteria();
        criteria.andEqualTo(ItemParamValue :: getItemId,itemId);
        return itemParamValueMapper.selectByExample(weekend);
    }

    @Override
    public List<ItemParamValue> find(Long[] ids) {
        Weekend<ItemParamValue> example = Weekend.of(ItemParamValue.class);
        WeekendCriteria<ItemParamValue,Object> criteria = example.weekendCriteria();
        criteria.andIn(ItemParamValue :: getParamId, Arrays.asList(ids));
        return itemParamValueMapper.selectByExample(example);
    }
}
